package cn.njxzc.examples;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.Collections;
import java.util.Comparator;

@SuppressWarnings("rawtypes")
class MySort implements Comparator {
	public int compare(Object o1, Object o2) {
		String s1 = (String) o1;
		String s2 = (String) o2;
		return s1.compareToIgnoreCase(s2);
	}

}

public class Exam8_13 {
	@SuppressWarnings({ "rawtypes", "unchecked" })
	public static void main(String[] args) {
		ArrayList list = new ArrayList();
		list.add("abc");
		list.add("DEF");
		list.add("ghi");
		Collections.sort(list);
		Iterator iter = list.iterator();
		System.out.println("默认的排序:");
		while (iter.hasNext())
			System.out.println(iter.next());
		Collections.sort(list, new MySort());
		iter = list.iterator();
		System.out.println("指定的排序:");
		while (iter.hasNext())
			System.out.println(iter.next());
	}

}
